package handler

import (
	"context"
	api "gitee.com/perception-network/block-chain-released/api/protos/blockChain/v1alpha"
	"gitee.com/perception-network/block-chain-released/internal/service"
)

type publicChainBlock struct {
	svc service.BlockChainReleaser
	api.UnimplementedPublicBlockChainReleasedServer
}

func NewPublicChainBlock(svc service.BlockChainReleaser) *publicChainBlock {
	return &publicChainBlock{
		svc: svc,
	}
}

func (i *publicChainBlock) GetAllBlockChainReleased(ctx context.Context, req *api.GetAllBlockChainReleasedReq) (*api.GetAllBlockChainReleasedData, error) {
	data, err := i.svc.GetBlockChainReleaseData(ctx)
	if err != nil {
		return nil, HandleErr(err)
	}
	return &api.GetAllBlockChainReleasedData{Data: BlockChainReleasesToPB(data)}, nil
}
